<template>
  <BasicTable @register="registerTable" class="w-4/4 xl:w-5/5" style="height: auto !important;">
    <template #tableTop v-if="isArray(tableConfig)">
          <div>
           <RadioGroup v-model:value="currentTab" button-style="solid">
            <RadioButton
              v-for="(item, index) in tableConfig"
              :key="index"
              :value="index">{{item.title.split('（')[0]}}</RadioButton>
          </RadioGroup>
          </div>
    </template>
  </BasicTable>
</template>

<script lang="ts" setup>
import { ref, defineProps, defineEmits,watch, defineExpose, nextTick, computed } from 'vue'
import { BasicTable, useTable } from '@/components/Table'
import { getSearchFormSchema1 } from './data'
import { RadioGroup, RadioButton } from 'ant-design-vue'
import  { modifyGroupValData } from '@/api/power/electricity/electricity'
import { isArray } from '@/utils/is'
const props = defineProps({
  tableConfig: {
    type: [Object, Array],
    default: () => {}
  },
  isCanResizeParent: {
    type: Boolean,
    default: true
  },
  pagination: {
    type: [Object,Boolean],
    default: false
  }
})
const currentTab = ref(0)
const tableInfo = computed(() => {
  if (isArray(props.tableConfig)) {
      return props.tableConfig[currentTab.value]
  } else {
    return props.tableConfig
  }
})
watch(() => tableInfo.value, (val) => {
  console.log(props.isCanResizeParent)
  nextTick(() => {
    if (val.columns) {
      setColumns(val.columns)
    }
    if (val.tableData) {
      setTableData(val.tableData)
    }
    console.log(getRawDataSource(), 'getRawDataSource')
  })
  if (val.title) {
    setTimeout(() => {
      setProps({
        title: val.title
      })
      
    },0)
  }
}, {
  immediate: true
})
const emit=defineEmits(['handleSearch'])
console.log(props.isCanResizeParent)
const [registerTable, { setColumns, getForm, setProps, setTableData, getRawDataSource }] = useTable({
  searchInfo: {},
  dataSource: [],
  title: '',
  rowKey: 'id',
  columns: [],
  useSearchForm: false,
  isCanResizeParent: props.isCanResizeParent,
  formConfig: {
    labelWidth: 120,
    schemas: getSearchFormSchema1({}),
    autoSubmitOnEnter: true,
    submitFunc: handleSearch
  },
  pagination: props.pagination,
  
  showTableSetting: false,
  bordered: true,
  beforeEditSubmit: async ({record,index,key,value, column}) => {
    console.log(record,index,key,value)
    const params = {
      id: value.id,
      dataVal: value.value,
      queryType: value.queryType
    }
    await modifyGroupValData(params)
  }
});
async function handleSearch() {
  const params = await getForm().getFieldsValue()
  emit('handleSearch', params)
}
defineExpose({getForm, handleSearch, getRawDataSource})
</script>

<style lang="less" scoped>
</style>


